package com.shiqu.web.bo;

import java.util.List;
import java.util.Map;

import com.shiqu.core.util.StringUtils;

/**
 * 分页查询参数
 *
 * @param <E>
 * @param total 总记录数
 * @param pages 总页数
 */
public class Page<E> {
	//分页pageNum
    private int pageNum=1;
    //页大小
    private int pageSize=10;
    //默认page 页码
    public static final int INIT_PAGE_NUM = 1;
    //默认的page 大小
    public static final int INIT_PAGE_SIZE = 10;
    //起始记录索引
    private int startRow;
    //结束记录索引
    private int endRow;
    //总记录数
    private long total;
    
    private int pages;
    //分页数据
    private List<E> result;

    
    public Page(int pageNum, int pageSize) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.startRow = pageNum > 0 ? (pageNum - 1) * pageSize : 0;
        this.endRow = pageNum * pageSize;
    }
    /**
     * 初始化page对象
     * @param paramMap 
     * @return
     */
    public static Page initPage(Map<String, Object> paramMap){
    	//初始化page参数	页面大小
		int pageSize = StringUtils.isNull(paramMap.get("pageSize"))?INIT_PAGE_SIZE:Integer.valueOf((String) paramMap.get("pageSize")) ;
		//页码数
		int pageNum = StringUtils.isNull(paramMap.get("pageNum"))?INIT_PAGE_NUM:Integer.valueOf( (String) paramMap.get("pageNum"));
		//初始化page对象
		Page page = new Page(pageNum,pageSize);
		return page;
    	
    }
    public List<E> getResult() {
        return result;
    }

    public void setResult(List<E> result) {
        this.result = result;
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    public int getEndRow() {
        return endRow;
    }

    public void setEndRow(int endRow) {
        this.endRow = endRow;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getStartRow() {
        return startRow;
    }

    public void setStartRow(int startRow) {
        this.startRow = startRow;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    @Override
    public String toString() {
        return "Page{" +
                "pageNum=" + pageNum +
                ", pageSize=" + pageSize +
                ", startRow=" + startRow +
                ", endRow=" + endRow +
                ", total=" + total +
                ", pages=" + pages +
                '}';
    }
}